<?php

declare(strict_types=1);

namespace app\admin\controller;

use app\common\model\GmTgczlogsTqk as TQK;

use think\facade\Request;



// $actorname='';
// $serverid='';

// if($_GET){
//     $actorname=$_GET['actorname'];
//     $serverid=$_GET['serverid'];
// }

//测试：http://101.33.245.40:7999/admin.php/api/indexTqk
class Api extends Base
{
    // 首页
    public function indexTqk($account, $serverid)
   // public function indexTqk()
    {
        // $qweqwe=Request::post('account');

        // return json(['test'=>$account]);
        $querytqk = TQK::getqueryList($account, $serverid);
      //$querytqk = TQK::getqueryList('xl718696', '1003');
        $cardTH = array(
            '10031' => array('name' => '200砸蛋卡', 'huode' => '30000', 'img' => '\drawal\draw\thdk.png'),
            '10021' => array('name' => '100砸蛋卡', 'huode' => '10000', 'img' => '\drawal\draw\shzk.png'),
            '10011' => array('name' => '50砸蛋卡', 'huode' => '3000', 'img' => '\drawal\draw\jzxk.png')
        );

        $matchedCards = array();

        foreach ($querytqk as $item) {
            $tqktype = $item['tqktype'];
            $symonth = $item['symonth'];
            if (array_key_exists($tqktype, $cardTH)) {
                $matchedCards[] = array(
                    'symonth' => $symonth,
                    'cardType' => $tqktype,
                    'cardName' => $cardTH[$tqktype]['name'],
                    'getB' => $cardTH[$tqktype]['huode'],
                    'pic' => $cardTH[$tqktype]['img']
                );
            }
        }
        $hasValidCardType = false;  
     foreach ($matchedCards as $card) {  
            if (!empty($card['cardType'])) {  
             $hasValidCardType = true;  
              break; 
    }  
}  


        return $this->fetch('indexTqk', ['querytqk' => $querytqk, 'matchedCards' => $matchedCards,'hasValidCardType'=>$hasValidCardType]);
    }
}
